/**
 *
 */
import Util;
import OpenApi;
import OpenApiUtil;
import EndpointUtil;

extends OpenApi;


init(config: OpenApi.Config){
  super(config);
  @endpointRule = '';
  
  checkConfig(config);
  @endpoint = getEndpoint('ddosdiversion', @regionId, @endpointRule, @network, @suffix, @endpointMap, @endpoint);
}

function getEndpoint(productId: string, regionId: string, endpointRule: string, network: string, suffix: string, endpointMap: map[string]string, endpoint: string) throws: string{
  if (!Util.empty(endpoint)) {
    return endpoint;
  }
  
  if (!Util.isUnset(endpointMap) && !Util.empty(endpointMap[regionId])) {
    return endpointMap[regionId];
  }
  return EndpointUtil.getEndpointRules(productId, regionId, endpointRule, network, suffix);
}

model ConfigNetStatusRequest {
  net?: string(name='Net', description='The CIDR block of the anti-DDoS diversion instance.

This parameter is required.', example='192.168.XX.XX/22'),
  regions?: [ string ](name='Regions', description='The regions in which the CIDR block needs to be advertised or withdrawn from advertising. If you leave this parameter empty, the CIDR blocks in all regions are configured.

>  You can call the [QueryNetList](https://help.aliyun.com/document_detail/2639086.html) operation to obtain the regions of the CIDR blocks.'),
  saleId?: string(name='SaleId', description='The ID of the anti-DDoS diversion instance.

This parameter is required.', example='ddos_diversion_public_cn-xxxxxxxxxxxxx'),
  status?: string(name='Status', description='The status of the CIDR block. Valid values:

*   enable: advertises the CIDR block.
*   disable: withdraws the advertising of the CIDR block.

This parameter is required.', example='enable'),
  subNets?: [ string ](name='SubNets', description='The subnet CIDR blocks of the CIDR block.'),
}

model ConfigNetStatusResponseBody = {
  code?: long(name='Code', description='The status code.

*   **200**: The request was successful.
*   Other codes: The request failed.', example='200'),
  message?: string(name='Message', description='The response parameters.', example='successful'),
  requestId?: string(name='RequestId', description='The request ID.', example='B0949F09-B9C1-1D5E-8F27-0A5BF3CD5D95'),
}

model ConfigNetStatusResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ConfigNetStatusResponseBody(name='body'),
}

/**
 * @summary Configures the advertising of a CIDR block.
 *
 * @param request ConfigNetStatusRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ConfigNetStatusResponse
 */
async function configNetStatusWithOptions(request: ConfigNetStatusRequest, runtime: Util.RuntimeOptions): ConfigNetStatusResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.net)) {
    query['Net'] = request.net;
  }
  if (!Util.isUnset(request.regions)) {
    query['Regions'] = request.regions;
  }
  if (!Util.isUnset(request.saleId)) {
    query['SaleId'] = request.saleId;
  }
  if (!Util.isUnset(request.status)) {
    query['Status'] = request.status;
  }
  if (!Util.isUnset(request.subNets)) {
    query['SubNets'] = request.subNets;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ConfigNetStatus',
    version = '2023-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Configures the advertising of a CIDR block.
 *
 * @param request ConfigNetStatusRequest
 * @return ConfigNetStatusResponse
 */
async function configNetStatus(request: ConfigNetStatusRequest): ConfigNetStatusResponse {
  var runtime = new Util.RuntimeOptions{};
  return configNetStatusWithOptions(request, runtime);
}

model ListInstanceRequest {
  name?: string(name='Name', description='The name of the instance.', example='test'),
  num?: long(name='Num', description='The number of entries per page. Default value: 100.', example='100'),
  page?: long(name='Page', description='The page number. Default value: 1', example='1'),
  saleId?: string(name='SaleId', description='The ID of the anti-DDoS diversion instance.', example='ddos_diversion_public_cn-xxxxxxxxxxxxx'),
  status?: string(name='Status', description='The status of the instance. Valid values:

- normal
- expired
- deleting
- stopped', example='normal'),
}

model ListInstanceResponseBody = {
  code?: long(name='Code', description='The status code.

- 200: The request was successful.
- Other codes: The request failed.', example='200'),
  data?: {
    instances?: [ 
      {
        comment?: string(name='Comment', description='The description.', example='description'),
        gmtCreate?: string(name='GmtCreate', description='The purchase time.', example='2022-12-15 11:10:42'),
        gmtExpire?: string(name='GmtExpire', description='The expiration time.', example='2023-02-23 00:00:00'),
        gmtModify?: string(name='GmtModify', description='The update time.', example='2022-12-15 11:10:42'),
        instanceId?: string(name='InstanceId', description='The alias of the instance.', example='ddos_diversion_public_cn-xxxxxxxxxxxxx_xxxxxx'),
        message?: string(name='Message', description='The configurations of the instance.', example='successful'),
        name?: string(name='Name', description='The name of the instance.', example='test'),
        saleId?: string(name='SaleId', description='The ID of the instance.', example='ddos_diversion_public_cn-xxxxxxxxxxxxx'),
        spec?: {
          coverage?: string(name='Coverage', description='The region of the asset.', example='international_and_hmt'),
          diversionType?: string(name='DiversionType', description='The diversion mode. Valid values: on-demand always-on', example='on-demand'),
          edition?: string(name='Edition', description='The mitigation plan.', example='enterprise'),
          idcNumbers?: string(name='IdcNumbers', description='The number of data centers. Valid values: 1 to 10.', example='1'),
          initialInstallation?: string(name='InitialInstallation', description='The initial installation mode.', example='gre_tunnel_by_pccw'),
          initialQty?: string(name='InitialQty', description='The initial installation quantity.', example='1'),
          ipSubnetNums?: string(name='IpSubnetNums', description='The number of CIDR blocks. Value range: 1 to 10000.', example='1'),
          mitigationAnalysis?: string(name='MitigationAnalysis', description='The mitigation analysis feature.', example='off'),
          mitigationAnalysisCapacity?: string(name='MitigationAnalysisCapacity', description='The log storage capacity.', example='3T'),
          mitigationCapacity?: string(name='MitigationCapacity', description='The maximum mitigation capability.', example='unlimited'),
          mitigationNums?: string(name='MitigationNums', description='The number of mitigation sessions.', example='unlimited'),
          normalBandwidth?: string(name='NormalBandwidth', description='The service traffic. Unit: Mbit/s.', example='100'),
        }(name='Spec', description='The specifications of the instance.'),
        status?: string(name='Status', description='The status of the instance. Valid values:

- normal
- expired
- deleting
- stopped', example='normal'),
        userId?: string(name='UserId', description='The user ID.', example='177xxxxxxxxxxxxx'),
      }
    ](name='Instances', description='The details of the anti-DDoS diversion instance.'),
    num?: long(name='Num', description='The number of entries per page.', example='100'),
    page?: long(name='Page', description='The page number.', example='1'),
    total?: long(name='Total', description='The total number of entries returned.', example='10'),
  }(name='Data', description='The returned result.'),
  message?: string(name='Message', description='The response parameters.', example='successful'),
  requestId?: string(name='RequestId', description='The request ID.', example='B0949F09-B9C1-1D5E-8F27-0A5BF3CD5D95'),
}

model ListInstanceResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: ListInstanceResponseBody(name='body'),
}

/**
 * @summary Queries anti-DDoS diversion instances.
 *
 * @param request ListInstanceRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return ListInstanceResponse
 */
async function listInstanceWithOptions(request: ListInstanceRequest, runtime: Util.RuntimeOptions): ListInstanceResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.name)) {
    query['Name'] = request.name;
  }
  if (!Util.isUnset(request.num)) {
    query['Num'] = request.num;
  }
  if (!Util.isUnset(request.page)) {
    query['Page'] = request.page;
  }
  if (!Util.isUnset(request.saleId)) {
    query['SaleId'] = request.saleId;
  }
  if (!Util.isUnset(request.status)) {
    query['Status'] = request.status;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'ListInstance',
    version = '2023-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries anti-DDoS diversion instances.
 *
 * @param request ListInstanceRequest
 * @return ListInstanceResponse
 */
async function listInstance(request: ListInstanceRequest): ListInstanceResponse {
  var runtime = new Util.RuntimeOptions{};
  return listInstanceWithOptions(request, runtime);
}

model QueryNetListRequest {
  mainNet?: string(name='MainNet', description='The primary CIDR block of the anti-DDoS diversion instance for which an extended CIDR block is configured. If no extended CIDR blocks are configured for the anti-DDoS diversion instance, leave this parameter empty.', example='192.168.XX.XX/22'),
  mode?: string(name='Mode', description='The scheduling mode. Valid values:

- manual: manual scheduling
- netflow-auto: automatic scheduling', example='netflow-auto'),
  net?: string(name='Net', description='The CIDR block of the anti-DDoS diversion instance.


> If no extended CIDR blocks are configured for the anti-DDoS diversion instance, this parameter specifies the CIDR block of the instance. If an extended CIDR block is configured for the anti-DDoS diversion instance, this parameter specifies the extended CIDR block that is configured for the instance. If this parameter is specified, the MainNet parameter is required.', example='192.168.XX.XX/24'),
  num?: long(name='Num', description='The number of entries per page. Default value: 100.', example='100'),
  page?: long(name='Page', description='The page number. Default value: 1', example='1'),
  saleId?: string(name='SaleId', description='The ID of the anti-DDoS diversion instance.', example='ddos_diversion_public_cn-xxxxxxxxxxxxx'),
}

model QueryNetListResponseBody = {
  code?: long(name='Code', description='The status code.

- 200: The request was successful.
- Other codes: The request failed.', example='200'),
  data?: {
    nets?: [ 
      {
        DDoSDefense?: {
          cleanTh?: {
            mbps?: int32(name='Mbps', description='The traffic scrubbing threshold in Mbit/s.', example='0'),
            pps?: int32(name='Pps', description='The traffic scrubbing threshold in packets per second (pps)', example='0'),
          }(name='CleanTh', description='The configuration of traffic scrubbing.'),
          djPolicy?: {
            policyName?: string(name='PolicyName', description='The name of the mitigation policy.', example='test_polilciy-xxx'),
          }(name='DjPolicy', description='The configuration of the mitigation policy.'),
          holeTh?: {
            threshMbps?: int32(name='ThreshMbps', description='The blackhole filtering threshold.', example='0'),
          }(name='HoleTh', description='The configuration of blackhole filtering.'),
        }(name='DDoSDefense', description='The DDoS mitigation configuration of the CIDR block.'),
        declared?: [ 
          {
            declared?: string(name='Declared', description='Indicates whether the CIDR block is advertised. Valid values:

- 0: The CIDR block is not advertised.
- 1: The CIDR block is advertised.', example='0'),
            region?: string(name='Region', description='The region in which the CIDR block is advertised.', example='oe26'),
          }
        ](name='Declared', description='The advertising details.'),
        declaredState?: int32(name='DeclaredState', description='The advertising status of the CIDR block. Valid values:
- 0: The CIDR block is not advertised.
- 1: The CIDR block is advertised.', example='1'),
        fwdEffect?: long(name='FwdEffect', description='Indicates whether the forwarding configuration takes effect. Valid values:

- 0: The forwarding configuration takes effect.
- 1: The forwarding configuration does not take effect.
- -1: The forwarding configuration is being deleted.', example='1'),
        gmtCreate?: string(name='GmtCreate', description='The creation time.', example='2023-02-23 00:00:00'),
        gmtModify?: string(name='GmtModify', description='The modification time.', example='2023-02-24 00:00:00'),
        mode?: string(name='Mode', description='The scheduling mode.', example='manual'),
        net?: string(name='Net', description='The CIDR block of the anti-DDoS diversion instance.', example='192.168.XX.XX/24'),
        netExtend?: string(name='NetExtend', description='Indicates whether the CIDR block needs to be extended. Valid values:

- 0: The CIDR block needs to be extended.
- 1: The CIDR block does not need to be extended.', example='1'),
        netMain?: string(name='NetMain', description='The primary CIDR block.', example='192.168.XX.XX/22'),
        netType?: string(name='NetType', description='The type of the CIDR block.', example='ipv4'),
        permit?: int32(name='Permit'),
        saleId?: string(name='SaleId', description='The ID of the anti-DDoS diversion instance.', example='ddos_diversion_public_cn-xxxxxxxxxxxxx'),
        upstreamType?: string(name='UpstreamType', description='The reinjection type.', example='aliyun_line'),
        userId?: string(name='UserId', description='The user ID.', example='177xxxxxxxxxxxxx'),
      }
    ](name='Nets', description='The configuration of the CIDR block.'),
    num?: long(name='Num', description='The number of entries per page.', example='100'),
    page?: long(name='Page', description='The page number.', example='1'),
    total?: long(name='Total', description='The total number of entries returned.', example='1'),
  }(name='Data', description='The CIDR blocks.'),
  message?: string(name='Message', description='The response parameters.', example='successful'),
  requestId?: string(name='RequestId', description='The request ID.', example='24B652B5-AEFF-3F03-9114-00D053C42277'),
}

model QueryNetListResponse = {
  headers?: map[string]string(name='headers'),
  statusCode?: int32(name='statusCode'),
  body?: QueryNetListResponseBody(name='body'),
}

/**
 * @summary Queries the CIDR blocks of an anti-DDoS diversion instance.
 *
 * @param request QueryNetListRequest
 * @param runtime runtime options for this request RuntimeOptions
 * @return QueryNetListResponse
 */
async function queryNetListWithOptions(request: QueryNetListRequest, runtime: Util.RuntimeOptions): QueryNetListResponse {
  Util.validateModel(request);
  var query = {};
  if (!Util.isUnset(request.mainNet)) {
    query['MainNet'] = request.mainNet;
  }
  if (!Util.isUnset(request.mode)) {
    query['Mode'] = request.mode;
  }
  if (!Util.isUnset(request.net)) {
    query['Net'] = request.net;
  }
  if (!Util.isUnset(request.num)) {
    query['Num'] = request.num;
  }
  if (!Util.isUnset(request.page)) {
    query['Page'] = request.page;
  }
  if (!Util.isUnset(request.saleId)) {
    query['SaleId'] = request.saleId;
  }
  var req = new OpenApi.OpenApiRequest{ 
    query = OpenApiUtil.query(query),
  };
  var params = new OpenApi.Params{
    action = 'QueryNetList',
    version = '2023-07-01',
    protocol = 'HTTPS',
    pathname = '/',
    method = 'POST',
    authType = 'AK',
    style = 'RPC',
    reqBodyType = 'formData',
    bodyType = 'json',
  };
  return callApi(params, req, runtime);
}

/**
 * @summary Queries the CIDR blocks of an anti-DDoS diversion instance.
 *
 * @param request QueryNetListRequest
 * @return QueryNetListResponse
 */
async function queryNetList(request: QueryNetListRequest): QueryNetListResponse {
  var runtime = new Util.RuntimeOptions{};
  return queryNetListWithOptions(request, runtime);
}

